package com.itheima.dao;

import com.itheima.pojo.WebVisit;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;


public interface WebVisitMapper extends Mapper<WebVisit> {

    //获取某一天的用户访问量(PV)
    @Select("SELECT COUNT(uid) FROM t_web_visit WHERE create_time>=#{day} AND create_time<#{nextDay}")
    int findPVCount(@Param("day") String day,@Param("nextDay") String nextDay);

    //统计七天内独立用户数(UV),目前通过ip来统计
    @Select("SELECT COUNT(ip) COUNT FROM (SELECT DISTINCT DATE_FORMAT(create_time, '%Y-%m-%d') DATE, ip FROM t_web_visit WHERE create_time >=#{day} AND create_time <#{nextDay} GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d'),ip) AS tmp GROUP BY DATE")
    Integer findUVCount(@Param("day") String day, @Param("nextDay") String nextDay);

    @Select("select count(*) from t_web_visit")
    int findVisitCount();
}
